home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / magix.c < prev    next >
C/C++ Source or Header  |  2000-05-22  |  5KB  |  231 lines

  1. /***************************************************************************
  2.  
  3.                                 -=  Magix  =-
  4.                              (c) 1995  Yun Sung
  5.  
  6.                 driver by    Luca Elia (eliavit@unina.it)
  7.  
  8.  
  9. Note:    if MAME_DEBUG is defined, pressing Z with:
  10.  
  11.         Q         shows the background layer
  12.         W         shows the foreground layer
  13.  
  14.         [ 2 Fixed Layers ]
  15.  
  16.             [ Background ]
  17.  
  18.             Layer Size:                512 x 256
  19.             Tiles:                    6 x 8 x 8 (!)
  20.  
  21.             [ Foreground ]
  22.  
  23.             Layer Size:                512 x 256
  24.             Tiles:                    8 x 8 x 4
  25.  
  26.  
  27.         There are no sprites.
  28.  
  29. ***************************************************************************/
  30. #include "vidhrdw/generic.h"
  31.  
  32.  
  33. /* Variables that driver has access to: */
  34.  
  35. unsigned char *magix_videoram_0,*magix_videoram_1;
  36.  
  37.  
  38. /* Variables only used here: */
  39.  
  40. static struct tilemap *tilemap_0, *tilemap_1;
  41. static int magix_videobank;
  42.  
  43.  
  44. /***************************************************************************
  45.  
  46.                             Memory Handlers
  47.  
  48. ***************************************************************************/
  49.  
  50. WRITE_HANDLER( magix_videobank_w )
  51. {
  52.     magix_videobank = data;
  53. }
  54.  
  55.  
  56. READ_HANDLER( magix_videoram_r )
  57. {
  58.     int bank;
  59.  
  60.     /*    Bit 1 of the bankswitching register contols the c000-c7ff
  61.         area (Palette). Bit 0 controls the c800-dfff area (Tiles) */
  62.  
  63.     if (offset < 0x0800)    bank = magix_videobank & 2;
  64.     else                    bank = magix_videobank & 1;
  65.  
  66.     if (bank)    return magix_videoram_0[offset];
  67.     else        return magix_videoram_1[offset];
  68. }
  69.  
  70.  
  71. WRITE_HANDLER( magix_videoram_w )
  72. {
  73.     if (offset < 0x0800)        // c000-c7ff    Banked Palette RAM
  74.     {
  75.         int bank = magix_videobank & 2;
  76.         unsigned char *RAM;
  77.         int r,g,b;
  78.  
  79.         if (bank)    RAM = magix_videoram_0;
  80.         else        RAM = magix_videoram_1;
  81.  
  82.         RAM[offset] = data;
  83.         data = RAM[offset & ~1] | (RAM[offset | 1] << 8);
  84.  
  85.         /* BBBBBGGGGGRRRRRx */
  86.         r = (data >>  0) & 0x1f;
  87.         g = (data >>  5) & 0x1f;
  88.         b = (data >> 10) & 0x1f;
  89.  
  90.         palette_change_color(offset/2 + (bank ? 0x400:0), (r << 3)|(r >> 2), (g << 3)|(g >> 2), (b << 3)|(b >> 2));
  91.     }
  92.     else
  93.     {
  94.         int tile;
  95.         int bank = magix_videobank & 1;
  96.  
  97.         if (offset < 0x1000)    tile = (offset-0x0800);        // c800-cfff: Banked Color RAM
  98.         else                     tile = (offset-0x1000)/2;    // d000-dfff: Banked Tiles RAM
  99.  
  100.         if (bank)    {    magix_videoram_0[offset] = data;
  101.                         tilemap_mark_tile_dirty(tilemap_0, tile);    }
  102.         else        {    magix_videoram_1[offset] = data;
  103.                         tilemap_mark_tile_dirty(tilemap_1, tile);    }
  104.     }
  105. }
  106.  
  107.  
  108. WRITE_HANDLER( magix_flipscreen_w )
  109. {
  110.     tilemap_set_flip(ALL_TILEMAPS, (data & 1) ? (TILEMAP_FLIPX|TILEMAP_FLIPY) : 0);
  111. }
  112.  
  113.  
  114.  
  115.  
  116. /***************************************************************************
  117.  
  118.                         Callbacks for the TileMap code
  119.  
  120. ***************************************************************************/
  121.  
  122.  
  123. /***************************************************************************
  124.  
  125.                               [ Tiles Format ]
  126.  
  127. Offset:
  128.  
  129.     Videoram + 0000.w        Code
  130.     Colorram + 0000.b        Color
  131.  
  132.  
  133. ***************************************************************************/
  134.  
  135. /* Background */
  136.  
  137. #define DIM_NX_0            (0x40)
  138. #define DIM_NY_0            (0x20)
  139.  
  140. static void get_tile_info_0( int tile_index )
  141. {
  142.     int code  =  magix_videoram_0[0x1000+tile_index * 2 + 0] + magix_videoram_0[0x1000+tile_index * 2 + 1] * 256;
  143.     int color =  magix_videoram_0[0x0800+ tile_index] & 0x07;
  144.     SET_TILE_INFO( 0, code, color );
  145. }
  146.  
  147. /* Text Plane */
  148.  
  149. #define DIM_NX_1            (0x40)
  150. #define DIM_NY_1            (0x20)
  151.  
  152. static void get_tile_info_1( int tile_index )
  153. {
  154.     int code  =  magix_videoram_1[0x1000+ tile_index * 2 + 0] + magix_videoram_1[0x1000+tile_index * 2 + 1] * 256;
  155.     int color =  magix_videoram_1[0x0800+ tile_index] & 0x3f;
  156.     SET_TILE_INFO( 1, code, color );
  157. }
  158.  
  159.  
  160.  
  161.  
  162. /***************************************************************************
  163.  
  164.  
  165.                                 Vh_Start
  166.  
  167.  
  168. ***************************************************************************/
  169.  
  170. int magix_vh_start(void)
  171. {
  172.     tilemap_0 = tilemap_create(    get_tile_info_0,
  173.                                 tilemap_scan_rows,
  174.                                 TILEMAP_OPAQUE,
  175.                                 8,8,
  176.                                 DIM_NX_0, DIM_NY_0 );
  177.  
  178.     tilemap_1 = tilemap_create(    get_tile_info_1,
  179.                                 tilemap_scan_rows,
  180.                                 TILEMAP_TRANSPARENT,
  181.                                 8,8,
  182.                                 DIM_NX_1, DIM_NY_1 );
  183.  
  184.     if (tilemap_0 && tilemap_1)
  185.     {
  186.         tilemap_1->transparent_pen = 0;
  187.         return 0;
  188.     }
  189.     else return 1;
  190. }
  191.  
  192.  
  193.  
  194. /***************************************************************************
  195.  
  196.  
  197.                                 Screen Drawing
  198.  
  199.  
  200. ***************************************************************************/
  201.  
  202. void magix_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  203. {
  204.     int layers_ctrl = -1;
  205.  
  206. #ifdef MAME_DEBUG
  207. if (keyboard_pressed(KEYCODE_Z))
  208. {
  209.     int msk = 0;
  210.     if (keyboard_pressed(KEYCODE_Q))    msk |= 1;
  211.     if (keyboard_pressed(KEYCODE_W))    msk |= 2;
  212.     if (msk != 0) layers_ctrl &= msk;
  213. }
  214. #endif
  215.  
  216.     tilemap_update(ALL_TILEMAPS);
  217.  
  218.     palette_init_used_colors();
  219.  
  220.     /* No Sprites ... */
  221.  
  222.     if (palette_recalc())    tilemap_mark_all_pixels_dirty(ALL_TILEMAPS);
  223.  
  224.     tilemap_render(ALL_TILEMAPS);
  225.  
  226.     if (layers_ctrl&1)    tilemap_draw(bitmap, tilemap_0, 0);
  227.     else                osd_clearbitmap(bitmap);
  228.  
  229.     if (layers_ctrl&2)    tilemap_draw(bitmap, tilemap_1, 0);
  230. }
  231.